<template>
	<view class="container">
		<view class="input-wrap">
			<input v-model="phone" type="number" placeholder="请输入手机号码" />
		</view>
		<view class="input-wrap fx jcb">
			<input v-model="captcha" type="number" maxlength="6" placeholder="请输入短信验证码" />
			<text class="fc_primary" @tap="getCode">{{verifyTips}}</text>
		</view>
		<view class="input-wrap">
			<input v-model="pass" password type="text" placeholder="请设置6-18位数字或字母的登录密码" />
		</view>
		<view class="input-wrap">
			<input v-model="passAgain" password type="text" placeholder="请再次输入修改的密码" />
		</view>
		<button class="btn custom_btn primary" @click="handleConfirm">确认修改</button>
		<u-toast ref="uToast"></u-toast>
		<u-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange" unique-key="check-phone"
			:keepRunning="true"></u-code>
	</view>
</template>

<script>
	import api from '@/service/config/api.js'
	import verifyCode from '@/mixins/verify_code.js'
	export default {
		mixins: [verifyCode],
		data() {
			return {
				phone: '', // 手机号
				captcha: '', // 验证码
				pass: '', // 密码
				passAgain: '', // 再次密码
			};
		},
		onLoad(options) {
			this.phone=options.phone ||""
		},
		methods: {
			getCode() {
				console.log(this.phone)
				if (!this.phone) return this.$utils.showToast("请填写手机号码");
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(this.phone)) return this.$utils.showToast('请输入正确的手机号码');
				api.get("/user/api/auth/sendLoginSms/" + this.phone,{},{noCheck: true}).then((res) => {
					this.showSend();
				});
			},
			handleConfirm() {
				if (!this.phone) return this.$utils.showToast('请填写手机号码');
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(this.phone)) return this.$utils.showToast('请输入正确的手机号码');
				if (!this.captcha) return this.$utils.showToast('请填写验证码');
				if (!this.pass) return this.$utils.showToast('请填写密码');
				if (this.passAgain !== this.pass) return this.$utils.showToast('两次输入密码不一致');
				if (!/^[\w\d]+$/i.test(this.captcha)) return this.$utils.showToast('请输入正确的验证码');
				if (this.passAgain.length<6 || this.passAgain.length>18 || !/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/)return this.$utils.showToast('请输入6-18位的数字或字母的登录密码');
				let reg1 = /[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/
				console.log(reg1.test(this.passAgain))
				this.$utils.loading();
				api.post('/user/api/auth/modifyPassword', {
					phone: this.phone,
					password:this.passAgain,
					code:this.captcha
				}).then(res => {
					this.$utils.showToast('修改成功',1500,0,'','success')
					setTimeout(()=>{
						uni.reLaunch({
							url: '/pages/account/pages/login'
						})
					},1500)
				}).catch(() => {
					uni.hideLoading()
				})

			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.container {
		padding: 0 32rpx;

		.input-wrap {
			height: 128rpx;
			box-sizing: border-box;
			padding-top: 46rpx;
			border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
			font-size: 32rpx;

			input {
				flex: 1;
			}

			.code-btn {
				margin: 0;
				padding: 0;
				width: 188rpx;
				line-height: 56rpx;
				height: 56rpx;
				background: rgba(95, 64, 235, 0.1);
				border-radius: 110rpx;

				&::after {
					content: none;
				}
			}
		}

		.btn {
			margin-top: 80rpx;
			line-height: 88rpx;
			border-radius: 112rpx;
			font-size: 32rpx;
		}
	}
</style>